package GameState;

import Main.GamePanel;
import TileMap.*;
import Entity.*;

import java.awt.*;
import java.awt.event.KeyEvent;

public class BoardState extends GameState {

    private TileMap tileMap;
    private Background bg;
    private Player player;
    private HUD hud;

    public BoardState(GameStateManager gsm) {
        this.gsm = gsm;
        init();
    }

    public void init() {

        tileMap = new TileMap(30);
        tileMap.loadTiles();
        tileMap.loadMap("/Maps/boardMap.map");
        tileMap.setPosition(0, 0);
        tileMap.setTween(1);

        bg = new Background("/ProjectPictures/zeddBackground.gif", 0.1);

        player = new Player(tileMap);
        hud = new HUD(player);
        player.setPosition(40, 300);

    }

    public void update() {

        // update player
        player.update();
        tileMap.setPosition(
                GamePanel.WIDTH / 2 - player.getx(),
                GamePanel.HEIGHT / 2 - player.gety());

    }

    public void draw(Graphics2D g) {

        // draw bg
        bg.draw(g);

        // draw tilemap
        tileMap.draw(g);

        // draw player
        player.draw(g);
        
        //draw HUD
        hud.draw(g);

    }

    public void keyPressed(int k) {
        if (k == KeyEvent.VK_LEFT) {
            player.setLeft(true);
        }
        if (k == KeyEvent.VK_RIGHT) {
            player.setRight(true);
        }
        if (k == KeyEvent.VK_DOWN) {
            player.setDown(true);
        }
        if (k == KeyEvent.VK_W) {
            player.setJumping(true);
        }
        if (k == KeyEvent.VK_E) {
            player.setSlowFalling(true);
        }
        if (k == KeyEvent.VK_R) {
            player.setSlashing();
        }
        if (k == KeyEvent.VK_F) {
            player.setFiring();
        }
    }

    public void keyReleased(int k) {
        if (k == KeyEvent.VK_LEFT) {
            player.setLeft(false);
        }
        if (k == KeyEvent.VK_RIGHT) {
            player.setRight(false);
        }
        if (k == KeyEvent.VK_DOWN) {
            player.setDown(false);
        }
        if (k == KeyEvent.VK_W) {
            player.setJumping(false);
        }
        if (k == KeyEvent.VK_E) {
            player.setSlowFalling(false);
        }
    }
}
